package com.ocom.mqsimple.config;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Lazy
@Component
@Configuration
public class UnicomMqConfig {

    // 业务队列
    public static final String UNICOM_QUEUE = "unicom_queue";

    // 业务交换机
    public static final String UNICOM_EXCHANGE = "unicom_exchange";

//    // 死信队列
//    public static final String UNICOM_DIE_QUEUE = "unicom_die_queue";
//    // 死信交换机
//    public static final String UNICOM_DIE_EXCHANGE = "unicom_die_exchange";


//    //声明一个死信队列用来存放死信消息
//    @Bean
//    public Queue unicomDieQueue() {
//        return new Queue(UNICOM_DIE_QUEUE, true, false, false, null);
//    }
//
//    //声明一个死信交换机
//    @Bean
//    public TopicExchange unicomDieExchange() {
//        return new TopicExchange(UNICOM_DIE_EXCHANGE, true, true);
//    }
//
//    //将死信队列和死信的交换机绑定
//    @Bean
//    public Binding unicomQueueBindingDieExchange() {
//        return BindingBuilder.bind(unicomDieQueue()).
//                to(unicomDieExchange()).
//                with("dieRoutingKeys");
//    }


    //声明一个业务队列
    @Bean
    public Queue unicomQueue() {
        Map<String, Object> args = new HashMap<>();
//        // 声明  死信队列Exchange
//        args.put("x-dead-letter-exchange", UNICOM_DIE_EXCHANGE);
//        // 设置死信routingKey
//        args.put("x-dead-letter-routing-key", "dieRoutingKeys");

        //优先级队列
        args.put("x-max-priority", 100);

        return new Queue(
                UNICOM_QUEUE,
                true,
                false,
                false, args);
    }

    //声明一个业务交换机
    @Bean
    public TopicExchange unicomExchange() {
        return new TopicExchange(UNICOM_EXCHANGE);
    }

    //将业务队列和业务交换机绑定
    @Bean
    public Binding unicomBindingDirect() {
        return BindingBuilder.bind(unicomQueue()).to(unicomExchange()).with("routingKeys");
    }


}

